package nio;

import java.math.BigDecimal;
import java.nio.Buffer;
import java.nio.IntBuffer;
import java.util.ArrayList;
import java.util.Objects;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

/**
 * @ClassName UseBuffer
 * @Description TODO
 * @Author leejiliang
 * @DateTime 2021/8/24 10:50
 * @Version 1.0
 */
public class UseBuffer {
    public static void main(String[] args) {
        final IntBuffer intBuffer = IntBuffer.allocate(20);
        printBuffer(intBuffer);
        IntStream.rangeClosed(1, 5).forEach(i -> intBuffer.put(i));
        printBuffer(intBuffer);
        intBuffer.flip();
        printBuffer(intBuffer);
        intBuffer.compact();
//		intBuffer.clear();
        printBuffer(intBuffer);
        intBuffer.flip();
        IntStream.rangeClosed(1, 2).forEach(i -> System.out.println(intBuffer.get()));
        printBuffer(intBuffer);
        intBuffer.mark();
        IntStream.rangeClosed(1, 3).forEach(i -> System.out.println(intBuffer.get()));
        printBuffer(intBuffer);
        intBuffer.reset();
        printBuffer(intBuffer);
//		intBuffer.get();
        intBuffer.rewind();
        printBuffer(intBuffer);
        final BigDecimal bigDecimal = BigDecimal.valueOf(100l);
        bigDecimal.intValue();
        ArrayList<Integer> objects = new ArrayList<>();

    }

    public static void printBuffer(Buffer buffer) {
        System.out.println(buffer.position());
        System.out.println(buffer.limit());
        System.out.println(buffer.capacity());
        System.out.println("===============================");
    }
}
